<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        /* .right{
            float:left;
            width: 100px;
            border: 3px solid palegoldenrod;
            padding: 10px;
        } */
    </style>
</head>

<body>
    <div id="app">
        <!-- 2、全局組件的使用 -->
        <btn v-bind:count="count1" @on-ok="change"></btn>
    </div>
</body>

</html>

<script>
    //ctrl+/生成單行注釋

    Vue.component("btn", {
        template: "<div><button v-on:click='add'>点击+1-当前值为：{{count}}</button></div>",
        data() {
            return {

            }
        },
        //接收父级传递的参数
        props: ['count'],
        methods: {
            add() {
                this.$emit("on-ok", this.count + 1)
            }
        }
    })

    new Vue({
        el: "#app", //必传
        data(){
            return {
                count1:0,
                count2:1000,
                msg1:"父组件中定义的变量1",
                msg2:"父组件中定义的变量2"
            }
        },
        methods:{
            change(data){
                console.log("子组件向父组件传递的值为：")
                console.log(data)
                this.count1 = data
            }
        }
    })

</script>